<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/WEB-INF/struts-tags.tld"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="Cache-Control" content="no-cache,must-revalidate">
	<link rel="stylesheet" href="<s:url value="/css/style_new.css"/>">
	<link rel="stylesheet" href="<s:url value="/css/style.css"/>">
	<script src="<s:url value="/script/jquery_last.js"/>" type="text/javascript"></script>
	<script type="text/javascript" src="<s:url value="/script/easyajax.js"/>"></script>
<STYLE>

</STYLE>


<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0">
<br/>
<table width="96%" border="0" cellspacing="0" cellpadding="0"
	align="center">
	<tr>
		<td width="20%" >
		<input type="button" name="bt" class="buttoncom4"  value="确 定" onclick="sure()"/>
		<input type="button" name="bt" class="buttoncom4"  value="关 闭" onclick="window.close();"/>
		</td>
	</tr>
</table>
<br/>
<table width="100%" border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<td width="96%" align="left">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
			人员名称
			<input type="text" name="pname" value="" size="220px">
			<input type="button" name="button" value="搜 索" onclick="findPersonByCond()">
		</td>
	</tr>
</table>
<table width="96%" border="0" cellspacing="0" cellpadding="0" align="center" class="tablelistnew">
	<tr>
		<td width="20%" align="center">公司</td>
		<td width="20%" align="center">一级部门</td>
		<td width="20%" align="center">二级部门</td>
		<td width="20%" align="center">人员</td>
		<td width="20%" align="center">已选择人员<a href="#" onclick="moveOption(selPerson,showPersons);"><u>&lt;清空&gt;</u></a></td>
	</tr>
	<tr>
		<td>
		<s:select list="corps" listKey="id" listValue="name" theme="css_xhtml" multiple="true" ondblclick="setDept(this)" cssClass="selStyle" id="corp"></s:select>
		</td>
		<td>
			<select name="depts" id="depts" class="selStyle" multiple="multiple" property="id" ondblclick="setSubDept(this)" labelProperty="name">
		</td>
		<td>
			<select name="subDepts" id="subDepts" class="selStyle" multiple="multiple" property="id" ondblclick="setPerson(this)" labelProperty="name">
		</td>
		<td>
			<select name="persons" id="persons" class="selStyle" multiple="multiple" property="id" labelProperty="name" ondblclick="addPerson()">
		</td>
		<td>
			<select name="selectedPerson" id="selectedPerson" class="selStyle" multiple="multiple" ondblclick="deletePerson()">
		</td>
	</tr>
</table>
</body>
</html>
<script>
<!--
/*初始化页面数据*/
initPage();

/*定义*/
var deptAjax=new AjaxObj();
var subDeptAjax=new AjaxObj();
var personAjax=new AjaxObj();

var corpID=$("corp");
var deptID=$("depts");
var subDeptID=$("subDepts");
var showPersons=$("persons");
var selPerson=$("selectedPerson");

/*清除列表*/
function clearList(sel){
	if(sel&&sel.options&&sel.options.length>0){
		for(var i=sel.options.length;i>0;i--){
			sel.removeChild(sel.options[i-1]);
		}
	}
}
/*清除*/
function clearCorp(){
	clearList(deptID);
	clearList(subDeptID);
	clearList(showPersons);
	clearList(selPerson);
}
function clearDept(){
	clearList(subDeptID);
	clearList(showPersons);
	clearList(selPerson);
}
function clearSubDept(){
	clearList(showPersons);
	clearList(selPerson);
}
function clearPerson(){
	clearList(selPerson);
}

/*保存并返回*/
function sure(){
	var obj=$("selectedPerson");
	var len=$("selectedPerson").options.length;
	if (len<1){
		if (confirm("您未选择人员.确定要退出吗？")){
			window.close();
		}else{
			return;
		}
	}
	var arrReturn=new Array();
	var returnVal="";
	var returnName="";
	for (i=0;i<len;i++){
		if (returnVal==""){
			returnVal=obj.options[i].value;
			returnName=obj.options[i].text;	
		}else{
			returnVal+=","+obj.options[i].value;
			returnName+=","+obj.options[i].text;	
		}		
	}
	arrReturn[0]=returnVal;
	arrReturn[1]=returnName;	
	window.returnValue=arrReturn;
	window.close();
}
/*初始化已选择数据*/
function initPage(){
	var objVal='<s:property value="returnObj"/>';
	var objName='<s:property value="returnObjName"/>';
	
	var objVals=window.dialogArguments.document.all[objVal];
	var objnames=window.dialogArguments.document.all[objName];
	if(objVals){
		var val=objVals.value;
		var name=objnames.value;
		if (val!=""){
			var ids=val.split(",");
			var names=name.split(",");
			if (ids.length && ids.length>0){
				for (i=0;i<ids.length;i++){
				    var option=document.createElement("option");
			    	option.value=ids[i];
			    	option.text=names[i];
					$("selectedPerson").add(option);
				}
			}
		}
	}
}


function setDept(obj){
	var cropId=getListValue(obj);
	if(cropId){
		clearCorp();
		callSynchronized("<s:url value="/organ/findOrganization.action"/>?codeId=FJ07&corpID="+cropId,function(XML){//同步调用
			deptAjax=new AjaxObj();
			deptAjax.xml=XML.responseXML;
			deptAjax.menuId="depts";
		  deptAjax.createMenu();
		});
	}
}

function setSubDept(obj){
	var cropId=getListValue(obj);
	if(cropId){
		clearDept();
		callSynchronized("<s:url value="/organ/findOrganization.action"/>?corpID="+cropId,function(XML){//同步调用
			subDeptAjax=new AjaxObj();
			subDeptAjax.xml=XML.responseXML;
			subDeptAjax.menuId="subDepts";
		  subDeptAjax.createMenu();
		});
		callSynchronized("<s:url value="/organ/findPersonByOrg.action"/>?corpID="+cropId,function(XML){//同步调用
			personAjax=new AjaxObj();
			personAjax.xml=XML.responseXML;
			personAjax.menuId="persons";
		  personAjax.createMenu();
		});
	}
}

function setPerson(obj){
	var cropId=getListValue(obj);
	if(cropId){
		clearSubDept();
		callSynchronized("<s:url value="/organ/findPersonByOrg.action"/>?corpID="+cropId,function(XML){//同步调用
			personAjax=new AjaxObj();
			personAjax.xml=XML.responseXML;
			personAjax.menuId="persons";
		  personAjax.createMenu();
		});
	}
}

function findPersonByCond(){
	var pname=document.all['pname'].value;
	if(pname){
		clearSubDept();
		callSynchronized("<s:url value="/organ/findPersonByCond.action"/>?corpID="+encodeURIComponent(pname),function(XML){//同步调用
			personAjax=new AjaxObj();
			personAjax.xml=XML.responseXML;
			personAjax.menuId="persons";
		  personAjax.createMenu();
		});
	}
}
/*新增关联产品*/
function addPerson(){
	moveOption(selPerson,showPersons);
	addOption(showPersons,selPerson);
}
/*删除关联产品*/
function deletePerson(){
	addOption(selPerson,showPersons);
}

function addOption(sour,obj){
	for(i=sour.options.length-1;i>-1;i--){
		if(sour.options[i].selected==true){
		  var option=document.createElement("option");
	    option.value=sour.options[i].value;
	    option.text=sour.options[i].text;
			obj.add(option);
			sour.remove(i);
		}
	}
}
function moveOption(sour,obj){
	for(i=sour.options.length-1;i>-1;i--){
		  var option=document.createElement("option");
	    option.value=sour.options[i].value;
	    option.text=sour.options[i].text;
			obj.add(option);
			sour.remove(i);
	}
}

function getListValue(obj){
	if(obj&&obj.options&&obj.options.selectedIndex!=-1&&obj.options[obj.options.selectedIndex].value!=""){
		return obj.options[obj.options.selectedIndex].value;
	}
}
-->
</script>


